﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BeIT.MemCached;
using System.Web.UI;

namespace MemcachedViewStatePageAdapter
{
	public class PageAdapter : System.Web.UI.Adapters.PageAdapter
	{
		const string CacheName = "ViewStateCache";
		public override PageStatePersister GetStatePersister()
		{
			return new MemcachedPageStatePersister(this.Page);
		} 


		//protected override void LoadAdapterViewState(object state)
		
		#region IViewStateStore Members

		public string StoreViewstate(string oldViewstate)
		{
			string id = Guid.NewGuid().ToString();
			MemcachedClient.GetInstance(CacheName).Set(id, oldViewstate, DateTime.MaxValue);
			return id;
		}

		public string RetrieveViewstate(string viewstateKey)
		{
			return MemcachedClient.GetInstance(CacheName).Get(viewstateKey) as string;
		}

	 
		#endregion
	}
}
